#include "Sprite.h"

void Sprite::Draw(Renderer* renderer){
	if(renderer->BindTexture(texture))
		renderer->Draw(vertices, D3DPRIMITIVETYPE::D3DPT_TRIANGLESTRIP , 4);
}

void Sprite::Update(float timeBetweenUpdates){
	//Entity2D::Update(timeBetweenUpdates);
}

void Sprite::SetTexture(Texture::ptr _texture){
	texture = _texture;
}

const Texture::ptr Sprite::GetTexture(){
	return texture;
}

void Sprite::SetTextureArea(float x,float y,float width,float height){
	float texW = texture->GetWidht();
	float texH = texture->GetHeight();
	
	float U1 = x / texW;
	float U2 = (x + width) / texW;

	float V1 = y / texH;
	float V2 = (y + height) / texH;
	
	vertices[0].u = U1;
	vertices[0].v = V2;
	
	vertices[1].u = U1;
	vertices[1].v = V1;
	
	vertices[2].u = U2;
	vertices[2].v = V2;
	
	vertices[0].u = U2;
	vertices[0].v = V1;
}